package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.FyUsersEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.FySchoolEntity;
import io.renren.modules.sys.service.FySchoolService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-01 16:23:14
 */
@RestController
@RequestMapping("sys/fyschool")
public class FySchoolController {
    @Autowired
    private FySchoolService fySchoolService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:fyschool:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fySchoolService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{schoolId}")
    @RequiresPermissions("sys:fyschool:info")
    public R info(@PathVariable("schoolId") Integer schoolId){
        FySchoolEntity fySchool = fySchoolService.getById(schoolId);

        return R.ok().put("fySchool", fySchool);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:fyschool:save")
    public R save(@RequestBody FySchoolEntity fySchool){
        long time = new Date().getTime()/1000;
        fySchool.setCreateTime(Integer.parseInt(String.valueOf(time)));
        fySchoolService.save(fySchool);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:fyschool:update")
    public R update(@RequestBody FySchoolEntity fySchool){
        ValidatorUtils.validateEntity(fySchool);
        fySchoolService.updateById(fySchool);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:fyschool:delete")
    public R delete(@RequestBody Integer[] schoolIds){
        fySchoolService.removeByIds(Arrays.asList(schoolIds));

        return R.ok();
    }

    /**
     * 查询所有学校信息
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("sys:fyschool:alllist")
    public R alllist(){
        List<FySchoolEntity> alllist = fySchoolService.list(new QueryWrapper<FySchoolEntity>());
        return R.ok().put("alllist", alllist);
    }

}
